package gui;

import java.awt.Container;
import java.awt.Dimension;
import java.awt.GridLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;

import client.ConnectionData;


public class MainFrame extends JFrame {
	
	public JipTextfield reiter2HostField;
	public JTextField reiter2UsernameField;
	
	public JipTextfield reiter1HostField;
	public JTextField reiter1UsernameField;
	public JTextField reiter1PWField;

	private static final long serialVersionUID = 1L;
	
	public MainFrame(String title, ConnectionData clientData) {
		super(title);
		init(clientData);
	}

	private void init(ConnectionData clientData) {
		JButton button;
		
		Container contentPane = getContentPane();
		
		JTabbedPane tabbedPane = new JTabbedPane();

		JPanel reiter1Pane = new JPanel();
		JPanel reiter2Pane = new JPanel();
		
		reiter1Pane.setLayout(new GridLayout(5,2));
		reiter1Pane.add(new JLabel("Server Ip Adresse:"));
		reiter1Pane.add(new JLabel(""));
		
		reiter1HostField = new JipTextfield();
		reiter1HostField.setIP("127.0.0.1");
		reiter1Pane.add(reiter1HostField);
		reiter1Pane.add(new JLabel(""));
		
		reiter1Pane.add(new JLabel("Benutzername:"));
		reiter1Pane.add(new JLabel("Passwort:"));
		
		reiter1UsernameField = new JTextField("");
		reiter1Pane.add(reiter1UsernameField);
		reiter1PWField = new JTextField("");
		reiter1Pane.add(reiter1PWField);
		
		button = new JButton("Verbinden");
		button.addActionListener(new Reiter1ButtonListener(this));
		reiter1Pane.add(button);
		
		reiter2Pane.setLayout(new GridLayout(5,1));
		reiter2Pane.add(new JLabel("Server Ip Adresse:"));
		reiter2HostField = new JipTextfield();
		reiter2HostField.setIP("127.0.0.1");
		reiter2Pane.add(reiter2HostField);
		reiter2Pane.add(new JLabel("Benutzername:"));
		reiter2UsernameField = new JTextField("");
		reiter2Pane.add(reiter2UsernameField);
		
		button = new JButton("Registrieren");
		button.addActionListener(new Reiter2ButtonListener(clientData, this));
		reiter2Pane.add(button);
		
		tabbedPane.addTab("Verbinden", reiter1Pane);
		tabbedPane.addTab("Registrieren", reiter2Pane);
		
		contentPane.add(tabbedPane);
		
	}
	
	public static void main(String[] args) {
		ConnectionData clientData = new ConnectionData();
		JFrame frame = new MainFrame("SRN", clientData);
		frame.pack();
		frame.setSize(new Dimension(frame.getSize().width-5, frame.getSize().height));
		frame.setResizable(false);
		frame.setVisible(true);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
	

}
